using System;
using System.Collections.Generic;

namespace EPPlayer
{
    /// <summary>
    /// in EP, the Morph defines the Durability stat which is implemented here
    /// Morphs also come with free gear (included in the morph cost),
    /// so we add that as well.
    /// </summary>
    public class Morph : AttachableAttribute
    {
        public readonly string Type;
        public readonly string Advantages, Disadvantages;
        public List<string> Implants = new List<string>();
        public readonly int Durability;
        public readonly int CPCost;
        public const string AttributeColor = "Morph";

        internal Morph(
            string Name, 
            string Type,
            string Advantages,
            string Disadvantages,
            int Durability,
            int CPCost,
            Modifiers Modifiers,
            string Description)
            : base(Name, AttributeColor, Modifiers, Description)
        {
            this.Type = Type;
            this.Advantages = Advantages;
            this.Disadvantages = Disadvantages;
            this.Durability = Durability;
            this.CPCost = CPCost;
        }

        public override void OnAttach(Entity Entity)
        {
            base.OnAttach(Entity);

            float DrMultiplier = this.type == "Biomorph" ? 1.5F : 2F;
            Entity.SetRawValue("Durability", this.Durability);
            Entity.SetRawValue("Wound Threshold", this.Durability / 5);
            Entity.SetRawValue("Death Rating", Convert.ToInt32(this.Durability * DrMultiplier));

            foreach (var ImplantName in Implants)
            {
                var Implant = GameResources.Gear[ImplantName];
                Implant.Owner = this;
                Entity.Add(Implant);
            }
        }

        public override void OnDetach(Entity Entity)
        {
            base.OnDetach(Entity);

            Entity.SetRawValue("Durability", 0);
            Entity.SetRawValue("Wound Threshold", 0);
            Entity.SetRawValue("Death Rating", 0);
        }
        public string advantages
        {
            get { return this.Advantages; }
        }
        public string disadvantages
        {
            get { return this.Disadvantages; }
        }
        public string type
        {
            get { return this.Type; }
        }
        public int durability
        {
            get { return this.Durability; }
        }
        public int cpCost
        {
            get { return this.CPCost; }
        }
    }
}